//
//  SYRequestAPI+BaiBan.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/8/9.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#define kIsEqualToString(msg) [interaction.suffix isEqualToString:msg]
#import "SYRequestAPI+BaiBan.h"
#import "SYInteractionModel.h"

@implementation SYRequestAPI (BaiBan)
//创建辅导班级
+ (void)bb_tencentCreateTencentChatGroupTutorInfoId:(NSString *)tutorInfoid
                                   teacherAccountId:(NSString *)teacherAccountId
                                            success:(void(^)(id dataList))success
                                               fail:(FailBlock)fail
{
//
    NSString *url = @"TicService.svc/Tencent/v3/createTencentChatGroup";
    
    NSDictionary *dict = @{@"tutorInfoId":tutorInfoid,
                           @"teacherAccountId":teacherAccountId
                           };
    [SYRequestAPI postDataFromURLScheme:url parameterDictionary:dict success:^(id responseObject) {
        
    } fail:^(NSError *error) {
        
    }];
}
//获取腾讯im信息
+ (void)bb_TutorServiceImInfoToken:(NSString *)token
                           success:(void(^)(id dataList))success
                              fail:(FailBlock)fail
{
    NSString *url = @"TicService.svc/Tencent/v3/GetImInfo";
    
    NSDictionary *dict = @{
                           @"token":token
                           };
    
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        if (success) {
            success(responseObject[@"data"]);
        }
    } fail:^(NSError *error) {
        if (error) {
            fail(error);
        }
    }];
}
//获取云点播签名
+ (void)bb_TutorServiceCloudPlaySignToken:(NSString *)token
                                  success:(void(^)(id dataList))success
                                     fail:(FailBlock)fail
{
    NSString *url = @"GetCloudPlaySign";
    NSDictionary *dict = @{
                           @"token":token
                           };
    [SYRequestAPI bb_postDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        if (success) {
            success(responseObject[@"data"]);
        }
    } fail:^(NSError *error) {
        if (error) {
            fail(error);
        }
    }];
    
}

//老师进入房间
+ (void)bb_TutorServiceJoinClassLessonAccountId:(NSString *)accountId
                                  tutorRecordId:(NSString *)tutorRecordId
                                        success:(void(^)(id dataList))success
                                           fail:(FailBlock)fail
{
    NSString *url = @"http://apipc.31waiyu.com/TutorService.svc/JoinClassLesson";
    
    NSDictionary *dict = @{
                           @"AccountId":accountId,
                           @"TutorRecordId":tutorRecordId
                           };
    
    [SYRequestAPI bb_postDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        
        NSString  *returnvalue = [responseObject nilObjectForKey:@"ReturnValue"];
        if (success) {
            success(returnvalue);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
        
    }];
    
}
//老师退出房间
+ (void)bb_TutorServiceExitClassLessonTeacherRecordId:(NSString *)teacherRecordId
                                              success:(void(^)(id dataList))success
                                                 fail:(FailBlock)fail
{
    NSString *url = @"http://apipc.31waiyu.com/TutorService.svc/ExitClassLesson";
    
    NSDictionary *dict = @{
                           @"TeacherRecordId":teacherRecordId,
                           };
    
    [SYRequestAPI bb_postDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        if (success) {
            success([responseObject nilObjectForKey:@"ReturnValue"]);
        }
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}
//更新上课状态
+ (void)bb_TutorServiceSetTutorInfoStatusTutorRecordId:(NSString *)tutorRecordId
                                                status:(NSString *)status
                                               success:(void(^)(id dataList))success
                                                  fail:(FailBlock)fail
{
    NSString *url = @"http://apipc.31waiyu.com/TutorService.svc/SetTutorInfoStatus";
    
    NSDictionary *dict = @{
                           @"TutorRecordId":tutorRecordId,
                           @"status":status
                           };
    
    [SYRequestAPI bb_postDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        if (success) {
            success([responseObject nilObjectForKey:@"ReturnValue"]);
        }
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}

+ (void)bb_TutorServicesSetTutorStudentInfoTutorId:(NSString *)tutorId
                                           success:(void(^)(NSMutableArray *dataListArr))success
                                              fail:(FailBlock)fail
{
    
    NSString *url = @"GetTutorClassUserInfo";
    
    NSDictionary *dict = @{
                           @"TutorId":tutorId
                           };
    
    [SYRequestAPI bb_postDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        NSArray *returnValueArr = [responseObject nilObjectForKey:@"ReturnValue"];
        NSMutableArray *dataListArr = [NSMutableArray array];
        for (NSDictionary *diction in returnValueArr) {
            SYInteractionStudentModel *studentModel = [SYInteractionStudentModel yy_modelWithJSON:diction];
            [dataListArr addObject:studentModel];
        }
        if (success) {
            success(dataListArr);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
    
}


+ (void)bb_TutorResourceInfoTutorId:(NSString *)tutorId
                         templateId:(NSString *)templateId
                            success:(void(^)(NSMutableArray *dataListArr))success
                               fail:(FailBlock)fail
{
    NSString *url = @"common/CommonService.svc/GetResourceInfo";
    
    NSDictionary *dict = @{
                           @"tutorId":tutorId
                           };
    
    [SYRequestAPI postDataFromURLScheme:url parameterDictionary:dict success:^(id responseObject) {
        
        NSArray *dataArr = responseObject[@"data"];
        NSMutableArray *listArr = [NSMutableArray array];
        for (NSDictionary *dict in dataArr) {
            if (![[dict nilObjectForKey:@"suffix"] containsString:@"mp4"]) {
                SYInteractionZiYuanModel *interaction = [SYInteractionZiYuanModel yy_modelWithDictionary:dict];
                //图片
                if (kIsEqualToString(@"jpg") || kIsEqualToString(@"bmp")||kIsEqualToString(@"png")) {
                    interaction.suta = SYInteractionTypeTuPian;//图片
                } else if (kIsEqualToString(@"doc")||kIsEqualToString(@"docx")||kIsEqualToString(@"pdf")||kIsEqualToString(@"pptx")||kIsEqualToString(@"ppt")) {
                    interaction.suta = SYInteractionTypeWenDang;
                } else {
                    interaction.suta = SYInteractionTypeRedundant;
                }
                
                //替换某个字符
                interaction.path = [interaction.path stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
                interaction.path = [interaction.path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
                [listArr addObject:interaction];
            }
            
        }
        if (success) {
            success(listArr);
        }
        
    } fail:^(NSError *error) {
        
        if (error) {
            fail(error);
        }
        
    }];
    
}

+ (void)bb_TutorClassServicePushTutorId:(NSString *)tutorId
                          TutorRecordId:(NSString *)TutorRecordId
                                 RoomID:(NSString *)RoomID
                               RoomIMID:(NSString *)RoomIMID
                               RoomName:(NSString *)RoomName
                             TeaAccount:(NSString *)TeaAccount
                                success:(void(^)(BOOL isSuccess))success
                                   fail:(FailBlock)fail
{
    NSDictionary *dict = @{@"TutorId":tutorId,
                           @"TutorRecordId":TutorRecordId,
                           @"RoomID":RoomID,
                           @"RoomIMID":RoomIMID,
                           @"RoomName":RoomName,
                           @"TeaAccount":TeaAccount
                           };
    NSString *url = @"tutor/TutorClassService.svc/TutorInClassPushMsg";
    [SYRequestAPI postDataFromURLScheme:url parameterDictionary:dict success:^(id responseObject) {
        if (success) {
            success(YES);
        }
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}

+ (void)bb_TutorStartRecordRoomId:(NSString *)roomId
                          success:(void(^)(BOOL isSuccess,NSString *info))success
                             fail:(FailBlock)fail {
    
    NSDictionary *dict = @{@"room_id":roomId};
    NSString *url = @"TicService.svc/Tencent/v3/startRecord";
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        NSInteger code = [[responseObject nilObjectForKey:@"code"] integerValue];
        NSString *info = [responseObject nilObjectForKey:@"data"];
        if (success) {
            success(code,info);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
    
}

+ (void)bb_TutorStopRecordInfo:(NSString *)infoId
                       success:(void(^)(BOOL isSuccess,NSString *info))success
                          fail:(FailBlock)fail {
    NSDictionary *dict = @{@"task_id":infoId};
    NSString *url = @"TicService.svc/Tencent/v3/stopRecord";
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        NSInteger code = [[responseObject nilObjectForKey:@"code"] integerValue];
        NSString *info = [responseObject nilObjectForKey:@"msg"];
        if (success) {
            success(code,info);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}
//根据taskid 获取token
+ (void)bb_TutorVideoUrlByTaskId:(NSString *)taskid
                         success:(void(^)(NSString *pathUrl))success
                            fail:(FailBlock)fail
{
    NSDictionary *dict = @{@"task_id":taskid};
    
    NSString *url = @"TicService.svc/Tencent/v3/getVideoUrlByTaskId";
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        
        NSArray *arr = [responseObject nilObjectForKey:@"data"];
        NSString *info = @"";
        for (int i = 0; i < arr.count; i++ ) {
            
            NSDictionary *dic = arr[i];
            if (i == 0) {
                info = dic[@"video_url"];
            }
            
        }

        if (success) {
            success(info);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
    
}
/// 暂停录制
/// @param taskId 需要停止录制的任务id
/// @param success 1
/// @param fail 0
+ (void)bb_TutorPauseRecordTaskId:(NSString *)taskId
                          success:(void(^)(NSString *pathUrl))success
                             fail:(FailBlock)fail
{
    NSDictionary *dict = @{@"task_id":taskId};
    NSString *url = @"TicService.svc/Tencent/v3/pauseRecord";
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        //NSInteger code = [[responseObject nilObjectForKey:@"code"] integerValue];
        NSString *info = [responseObject nilObjectForKey:@"msg"];
        if (success) {
            success(info);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}


/// 恢复录制
/// @param taskId 任务id
/// @param success 1
/// @param fail 0
+ (void)bb_TutorResumeRecordTask:(NSString *)taskId
                         success:(void(^)(NSString *pathUrl))success
                            fail:(FailBlock)fail
{
    NSDictionary *dict = @{@"task_id":taskId};
    NSString *url = @"TicService.svc/Tencent/v3/resumeRecord";
    [SYRequestAPI bb_postTXDataFromURLSecheme:url parameterDictionary:dict success:^(id responseObject) {
        //NSInteger code = [[responseObject nilObjectForKey:@"code"] integerValue];
        NSString *info = [responseObject nilObjectForKey:@"msg"];
        if (success) {
           success(info);
        }
        
    } fail:^(NSError *error) {
        if (fail) {
            fail(error);
        }
    }];
}
@end
